<?php
require_once('../../includes/classes/core.php');
//asteriskcdrdb

header('Content-Type: application/json');
$start = $_REQUEST['start'];
$end   = $_REQUEST['end'];
$agentt = $_REQUEST['agent'];
$queuet = $_REQUEST['queuet'];

$quantity = array();
$cause = array();
$cause1 = array();

$name = array();
$agent = array();

$call_count = array();





$name[]     = '';


	$ress =mysql_query("SELECT	CASE
									WHEN dst_extension = 'ALF2' THEN 'მამუკა'
									WHEN dst_extension = 'ALF3' THEN 'ნინო'
									WHEN dst_extension = 'ALF4' THEN 'თამო'
									WHEN dst_extension = 'ALF5' THEN 'ლაშა'
									WHEN dst_extension = 'ALF6' THEN 'სალომე მიროტაძე'
									WHEN dst_extension = 'ALF7' THEN 'მარი კუპატაძე'
									WHEN dst_extension = 'ALF8' THEN 'ნინო ტოხიშვილი'
									WHEN dst_extension = 'ALF9' THEN 'რუსუდან ბოჭორიშვილი'
							    END AS `ageny`,
                                COUNT(*) AS `num`
                                
						FROM 	asterisk_incomming
                        WHERE 	disconnect_cause != 'ABANDON'
                        AND 	DATE(datetime) >= '$start'
                        AND 	DATE(datetime) <= '$end'
                        AND 	dst_queue IN ($queuet)
                        AND		dst_extension IN ($agentt)
						GROUP BY dst_extension");
			
while($row1 = mysql_fetch_assoc($ress)){

	$call_count[] = (float)$row1[num];
	$agent[]		= $row1[agent];
}

							
$unit[]="  ზარი";
$series[] = array('name' => $name, 'unit' => $unit, 'quantity' => $quantity, 'cause' => $cause);
$series[] = array('name' => $name, 'unit' => $unit, 'call_count' => $call_count, 'agent' => $agent);

echo json_encode($series);

?>